package com.heiliushu.baseWeb.service.impl.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import com.heiliushu.baseWeb.domain.entity.SecurityUser;
import com.heiliushu.baseWeb.domain.entity.User;
import com.heiliushu.baseWeb.domain.entity.UserInfo;
import com.heiliushu.baseWeb.service.system.UserService;

@Component
public class CustomUserDetailsService implements UserDetailsService {

	@Autowired
	private UserService userService;
	
	@Override
	public UserDetails loadUserByUsername(String loginName) throws UsernameNotFoundException {
		UserInfo user = userService.findByLoginName(loginName);
		if(user == null){
			throw new UsernameNotFoundException("LoginName "+loginName+" not found !");
		}
		return new SecurityUser(user);
	}

}
